package com.ruoyi.logistics.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.logistics.domain.TraceLngLat;
import com.ruoyi.logistics.mapper.TraceLngLatMapper;
import com.ruoyi.logistics.service.TraceTransportService;
import com.ruoyi.logistics.mapper.TraceTransportMapper;
import com.ruoyi.system.api.domain.TraceTransport;
import com.ruoyi.system.api.domain.vo.CropsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lx
 * @description 针对表【trace_transport(物流管理信息)】的数据库操作Service实现
 * @createDate 2023-05-29 09:50:00
 */
@Service
public class TraceTransportServiceImpl extends ServiceImpl<TraceTransportMapper, TraceTransport>
        implements TraceTransportService{
    @Autowired
    private TraceTransportMapper traceTransportMapper;

    @Autowired
    private TraceLngLatMapper traceLngLatMapper;

    @Override
    public List<TraceTransport> listTransport(String driverId) {

        return traceTransportMapper.listTransport(driverId);
    }

    @Override
    public int saveAndUpdateTransportInfoToDb(TraceLngLat traceLngLat) {
        TraceTransport traceTransport = new TraceTransport();
        traceTransport.setOutFactoryStatus(traceLngLat.getOutFactoryStatus());
        traceTransport.setId(traceLngLat.getId());
        traceTransport.setCropsId(traceLngLat.getCropsId());
        traceTransport.setStatus(traceLngLat.getStatus());

        traceLngLatMapper.insertSelective(traceLngLat);
        return traceTransportMapper.updateByCropsId(traceTransport);

    }

    @Override
    public int insertSelective(TraceTransport record) {

        return traceTransportMapper.insertSelective(record);
    }


    //---------------------------调用-----------------------------------


    /**
     * 根据部门id获取农作物列表
     *
     * @param deptId
     * @return
     */
    @Override
    public List<TraceTransport> listCrops(String deptId) {
        return traceTransportMapper.listCrops(deptId);
    }


    /**
     * 根据部门id获取农作物+物流列表
     *
     * @param deptId
     * @return
     */
    @Override
    public List<CropsVo> queryCropsList(Integer deptId) {
        return  traceTransportMapper.queryCropsList(deptId);
    }

    /**
     * 修改出库状态
     * @param cropsId
     * @return
     */
    @Override
    public int changeInToOut(String cropsId) {
        return traceTransportMapper.changeInToOut(cropsId);
    }

    /**
     * 添加物流信息
     * @param traceTransport
     * @return
     */
    @Override
    public int addTransport(TraceTransport traceTransport) {
        return traceTransportMapper.insertSelective(traceTransport);
    }

    @Override
    public int updateReceiveStatus(TraceTransport traceTransport) {
        return traceTransportMapper.updateReceiveStatus(traceTransport);
    }


}




